/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.jiadakeji.ppm.modules.business.service;

import com.jiadakeji.ppm.common.persistence.Page;
import com.jiadakeji.ppm.common.service.CrudService;
import com.jiadakeji.ppm.modules.business.dao.AskRoomDao;
import com.jiadakeji.ppm.modules.business.dao.RoomDao;
import com.jiadakeji.ppm.modules.business.entity.AskRoom;
import com.jiadakeji.ppm.modules.business.entity.Room;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 申请房屋Service
 * @author HHAOYU
 * @version 2019-08-19
 */
@Service
@Transactional(readOnly = true)
public class AskRoomService extends CrudService<AskRoomDao, AskRoom> {
	@Autowired
	private RoomDao roomDao;

	@Override
	public AskRoom get(String id) {
		return super.get(id);
	}

	@Override
	public List<AskRoom> findList(AskRoom askRoom) {
		return super.findList(askRoom);
	}

	@Override
	public Page<AskRoom> findPage(Page<AskRoom> page, AskRoom askRoom) {
		return super.findPage(page, askRoom);
	}

	@Override
	@Transactional(readOnly = false)
	public void save(AskRoom askRoom) {
		if(askRoom.getStatus().equals(AskRoom.STATUS_PASS)){
			Room room = roomDao.get(askRoom.getRoomId());
			room.setHouseHolderId(askRoom.getCustomerId());
			room.setUsingCustomerId(askRoom.getCustomerId());
			roomDao.update(room);

		}
		super.save(askRoom);
	}


	@Override
	@Transactional(readOnly = false)
	public void delete(AskRoom askRoom) {
		//TODO 删除其它关联表
		
		super.delete(askRoom);
	}

}